home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 November / PCWorld_2007-11_cd.bin / v cisle / dap / dap85.exe / %TEMPCABFULLDIR% / DapLang.cab / dapff.jar / content / dapclickHandle.js < prev    next >
Encoding:
JavaScript  |  2006-10-25  |  5.4 KB  |  246 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2. * Download Accelerator Plus Integration for Mozilla/Firefox. 
  3. *
  4. * The contents of this file may be used under the terms of 
  5. * Download Accelerator Plus (DAP) End User License Agreement, also 
  6. * available at http://www.speedbit.com/Legal/DAPLICENSE.ASP ,
  7. * and is subject to the Speedbit Privacy Policy, also available 
  8. * at http://www.speedbit.com/Legal/Privacy.ASP. 
  9. *
  10. * Copyright (C) 1999-2006 SpeedBit Ltd.
  11. ***** END LICENSE BLOCK *****/
  12.  
  13.  
  14. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. //  Init : global object and listener to click 
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. function Init()
  18. {
  19.     DAP_Log("init");
  20.     window.removeEventListener("load", Init, true);
  21.  
  22.     
  23.     gDAPService = Components.classes["@speedbit/dapcomponent-service;1"]
  24.         .getService(Components.interfaces.nsISupports).wrappedJSObject;
  25.  
  26.  
  27.     if( !gDAPService )
  28.         DAP_Log("problem create DAP service ");
  29.     
  30.  
  31.     if( gDAPService.isMinIntegration() )
  32.     {
  33.         DAP_Log("Min integration Init ");
  34.         return;
  35.     }
  36.  
  37.     DAP_Log(window.navigator.userAgent);
  38.  
  39.  
  40.  
  41.     var appcontent = document.getElementById("appcontent");   // browser
  42.     if(appcontent)
  43.    {
  44.       appcontent.addEventListener("load",myLoadPageExtention.onPageLoad, true);
  45.    }
  46.  
  47.   
  48.       var frames = document.getElementsByTagName ("iframe");
  49.     for( var i = 0; i < frames .length ; i++)
  50.     {
  51.         DAP_Log("Frames");
  52.         frames[i].addEventListener("load",myLoadPageExtention.onPageLoad, true);
  53.  
  54.     }
  55.     
  56. }
  57. ///////////////////////////////////////////////////////////////////////////////////////////////
  58.  
  59.  
  60. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. function FindParentNode (node, parentNode)
  62. {
  63.     DAP_Log("FindParentNode ");
  64.     if (node && node.nodeType == Node.TEXT_NODE)
  65.     {
  66.         node = node.parentNode;
  67.     }
  68.     while (node)
  69.     {
  70.         var nodeName = node.localName;
  71.         if (!nodeName)
  72.         {
  73.             return null;
  74.         }
  75.         nodeName = nodeName.toLowerCase();
  76.         if (nodeName == "body" || nodeName == "html" || nodeName == "#document")
  77.         {
  78.             return null;
  79.         }
  80.         if (nodeName == parentNode)
  81.         {
  82.             return node;
  83.         }
  84.         node = node.parentNode;
  85.     }
  86.     return null;
  87. }
  88.  
  89.  
  90. /////////////////////////////////////////////////////////////////////////////////////////////////
  91. //  Click monitor extention 
  92. ///////////////////////////////////////////////////////////////////////////////////////////////////
  93. var myClickExtention = 
  94. {
  95.  
  96. ClickLink : function ( event )
  97. {
  98.   DAP_Log("ClickLink");
  99.  
  100.     if( event.button == 0 && event.altKey )
  101.         return;
  102.  
  103.  try
  104.  {
  105.     // function check if had been install DAP 
  106.     if( !gDAPService._runDAP() )
  107.     {
  108.         DAP_Log("Dap not exist from click handler");
  109.         return;
  110.     }
  111.  
  112.     var target = event.target;
  113.  
  114.     var linkNode = null;
  115.     var localName = target.localName;
  116.     if (localName) { localName = localName.toLowerCase(); }
  117.     switch (localName)
  118.     {
  119.         case "a":
  120.         case "area":
  121.         case "link":
  122.             if (target.hasAttribute("href"))
  123.             {
  124.                 linkNode = target;
  125.             }
  126.             break;
  127.         default:
  128.             linkNode = FindParentNode(event.originalTarget, "a");
  129.             if (linkNode && !linkNode.hasAttribute("href"))
  130.             {
  131.                 linkNode = null;
  132.             }
  133.             break;
  134.     }
  135.  
  136.  
  137.     if (!linkNode)
  138.     {
  139.  
  140.         DAP_Log("Link node NULL");
  141.         return;
  142.     }
  143.  
  144.     
  145.         var href = linkNode.href;
  146.         if (!href)
  147.         {
  148.             var wrapper = new XPCNativeWrapper(linkNode, "href", "getAttribute()");
  149.             href = wrapper.href;
  150.         }
  151.  
  152.         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  153.         var obj = gDAPService.getDAPComponent();
  154.         if( !obj )
  155.         {
  156.             DAP_Log("create instance null");
  157.             return;
  158.         } 
  159.  
  160.         var doc = event.originalTarget.ownerDocument;
  161.         // reffer
  162.         var reffer = doc.location.href;
  163.         // cookies
  164.         var cook = doc.cookie;
  165.         // description 
  166.         var description =  getDescriptionFromDocument(linkNode.ownerDocument);
  167.  
  168.         DAP_Log(href);
  169.         DAP_Log(reffer);
  170.         DAP_Log(cook);
  171.         DAP_Log(description);
  172.         var userAgent = window.navigator.userAgent;
  173.  
  174.         if( event.button == 0 && event.altKey  && event.ctrlKey)
  175.         {
  176.                 DAP_Log(" press alt && click ");
  177.                 obj.SendToDAP(href,reffer,cook,description,userAgent);
  178.                 return;
  179.  
  180.         }
  181.         // new click ,ask again 
  182.         gDAPService.setRegularDownload(false);
  183.  
  184.  
  185.         if( !obj.IsShoudTrigger(href) )
  186.         {
  187.             DAP_Log("shoud trigger false");
  188.             return;
  189.         }
  190.         
  191.         if( !obj.IsAccelerate())
  192.         {
  193.                 // continue download with FireFox 
  194.                 gDAPService.setRegularDownload(true);
  195.                 return;
  196.         }
  197.  
  198.  
  199.         obj.SendToDAP(href,reffer,cook,description,userAgent);
  200.         event.preventDefault();
  201.         event.stopPropagation();
  202.             
  203.                 
  204.  }
  205.  catch(ex)
  206.  {
  207.    DAP_Log(ex);
  208.  }
  209.  
  210. }
  211.  
  212. };
  213. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  214. var myLoadPageExtention =
  215. {
  216.  
  217.   onPageLoad: function(aEvent) 
  218.     {
  219.  
  220.             DAP_Log("onPageLoad");
  221.             try
  222.             {
  223.             var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
  224.  
  225.                 if( !doc.links )
  226.                  return;
  227.  
  228.  
  229.                 for( var i = 0; i< doc.links.length ; i++ )   
  230.                         doc.links[i].addEventListener("click",myClickExtention.ClickLink,true);
  231.           
  232.         
  233.             }
  234.             catch(e)
  235.             {
  236.                     DAP_Log(e);
  237.             }
  238.   }
  239. };
  240.  
  241.  
  242. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  243.  
  244. // add overlay to load page 
  245. window.addEventListener("load", Init, true);
  246.